﻿
namespace Thor.WebRole.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Configuration;
    using System.IO;
    using System.Linq;
    using System.Web.DomainServices;
    using System.Web.Ria;
    using System.Web.Ria.Services;
    using Thor.Common;
    using Thor.Domain;
    using Thor.Domain.Configuration;

    [EnableClientAccess()]
    public class SettingsManagerDomainService : DomainService
    {
        public Settings GetSettings()
        {
            Settings settings = SettingsHelper.GetManager().Settings;

            if (settings != null)
            {
                settings.Encrypt();
                return settings;
            }
            else
                return new Settings();
        }

        public void SaveSettings(Settings settings)
        {
            if (settings != null)
            {
                var settingsManager = SettingsHelper.GetManager();
                settingsManager.Settings = settings;
                settingsManager.Save();

                var message = new Message() { Text = "Settings updated." };
                var messageManager = MessageHelper.GetMessageManager();
                messageManager.Insert(message);
            }
        }
    }
}